dofile ("adds.lua")

OS = {}

osx = 0
osy = 0

function OS.init ()
  OS.x = 0
  OS.y = 0
  OS.x2 = 256
  OS.y2 = 192
  
  OS.bx = 0
  OS.by = 0
  OS.bx2 = 256
  OS.by2 = 20
  OS.bm = newBox (OS.x+5, OS.y+5, OS.x+34, OS.y+17)
  
  OS.mx = OS.x
  OS.my = OS.y+20
  OS.mx2 = OS.x+100
  OS.my2 = OS.y2-20
  OS.mvisible = false
  
  OS.prog = "today.lua"
end

function OS.draw ()
  if Stylus.held then
    osx = Stylus.X
    osy = Stylus.Y
  end
  
  function OS.drawTB ()
    screen.drawGradientRect (SCREEN_DOWN, OS.bx, OS.by, OS.bx2, OS.by2, c_bleu, c_bleu, c_blanc, c_blanc)
    screen.drawRect (SCREEN_DOWN, OS.x+5, OS.y+5, OS.x+34, OS.y+17, c_blanc)
    screen.print (SCREEN_DOWN, OS.x+7, OS.y+7, "Menu")
    if Stylus.newPressinBox (OS.bm, osx, osy) and not OS.mvisible then
      OS.mvisible = true
    elseif Stylus.newPressinBox (OS.bm, osx, osy) and OS.mvisible then
      OS.mvisible = false
    end
  end
  
  function OS.drawMenu ()
    if OS.mvisible then
      screen.drawFillRect (SCREEN_DOWN, OS.mx, OS.my, OS.mx2, OS.my2, c_bleu)
    end
  end
  
  --OS.exeProg = loadfile (OS.prog)
  
  OS.drawTB ()
  OS.drawMenu ()
  screen.print (SCREEN_UP, 5, 5, "RAM : "..tostring (gcinfo ()).." kb")
  --OS.exeProg ()
end

function OS.clear ()
  OS = nil
  
  osx = nil
  osy = nil
end

OS.init ()

while not Keys.newPress.Start do
   
  Controls.read()
  
  startDrawing()
    
    OS.draw ()
    
  stopDrawing()

end

OS.clear ()

